﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestStockFormIn.aspx.cs" Inherits="Samples_TestStockFormIn" %>

<%@ Register src="../dotNetFlexGrid/dotNetFlexGrid.ascx" tagname="dotNetFlexGrid" tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
	<style type="text/css">
<!--
#divListModify {
	border: 1px solid #333333;
	height: 150px;
	width: 400px;
	position: relative;
}
body {
	font-size: 12px;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
	</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>

<body>
<script language="javascript" type="text/javascript" src="../res/dialog.js"></script>
<script language="javascript" type="text/javascript">
var dialog;
function newProd()
{
    $("#txtOpType").val('new');//设置操作类型为新增
    //清空面板中的文本框
    $('#divListModify input[type=text]').each(function(){
        $(this).val('1');
    });
    dialog = new Dialog({ type: 'id', value: 'divListModify' },{ title: '新建商品' });
    dialog.show();
}
function delProd(id)
{
    //直接删除了
    dotNetFlexGrid1.deleteRows([id]);
}
function editProd(id)
{
    if(id)
    {
        var array = dotNetFlexGrid1.getCellDatas(id);
        
        if(array&&array.length>0)
        {
            dialog = new Dialog({ type: 'id', value: 'divListModify' }, { title: '修改商品信息' });
            dialog.show();
            
            alert($('.dialog #txtPName')[0]);
            $('.dialog #txtPName').val(array[1]);
            $('.dialog #txtPNumber').val(array[2]);
            $('.dialog #txtPPrice').val(array[3].substring(1,array[3].length));
            $('.dialog #txtPCode').val(array[4]);

            $(".dialog #txtOpType").val('edt');
            $('.dialog #txtOpProdId').val(id);
            
        }
        
    }
}
function saveModify()
{
    var pname=$('#txtPName').val();
    var pnumber=$('#txtPNumber').val();
    var pprice='￥'+$('#txtPPrice').val();
    var pcode=$('#txtPCode').val();
    
    if($("#txtOpType").val()=='new')
    {
        var id='new_' + Math.round(Math.random() * 10000);
        dotNetFlexGrid1.insertNewRow({
                id: id, 
                cell: [
                        id,
                        pname,
                        pnumber,
                        pprice,
                        pcode,
                        '正常销售',
                        '<a href="javascript:editProd(\''+id+'\');">编辑</a>',
                        '<a href="javascript:delProd(\''+id+'\');">删除</a>',
                        $("#txtOpType").val()
                ]
            });
    }
    else if($("#txtOpType").val()=='edt')
    {
        var id = $('#txtOpProdId').val();
        
        var array=dotNetFlexGrid1.getCellDatas(id);
        alert(array.length);
        if (id && array && array.length > 0) {
            var isNew = (array[7] == 'new') ? true : false;
            dotNetFlexGrid1.updateRowData({
                 id: id,
                 cell: [
                        id,
                        pname,
                        pnumber,
                        pprice,
                        pcode,
                        '正常销售',
                        '<a href="javascript:editProd(\''+id+'\');">编辑</a>',
                        '<a href="javascript:delProd(\''+id+'\');">删除</a>',
                        (isNew)? 'new': $("#txtOpType").val()
                    ]
             });
         }
    }

    if(dialog)
		dialog.close();
}
function cancelModify()
{
	if(dialog)
		dialog.close();
}
function Grid1DbClick(id) {
    editProd(id);    
}
function formSubmit() {
    var lstData = $('#<%=txtListData.ClientID %>');
    $(lstData).val(dotNetFlexGrid1.getGridJsonData());
    return true;
}


function JT_init(){
alert($('#TextBox1')[0]);
	       $('#TextBox1')
		   .hover(function(){JT_show(this.href,this.id,this.name)},function(){$('#JT').remove()})
           .click(function(){return false});	   
}
</script>
<link href="../res/dialog.css" rel="stylesheet" type="text/css" />
<form id="form1" runat="server" onsubmit="return formSubmit();">
<div id="divMain" runat=server>
    
    <div id="divList">
        <table width="600" border="1" align="left" cellpadding="2" cellspacing="4" bordercolor="#FFFFFF">
		    <tr>
				    <td align="center" bordercolor="#333333" bgcolor="#33CCFF">
					<table width="100%" border="0" cellspacing="2" cellpadding="2">
							<tr>
									<td width="15%" align="left"><div align="left">单据编号：</div></td>
									<td width="32%" align="left"><asp:TextBox ID="txtCode" runat="server" TextMode="SingleLine"></asp:TextBox></td>
									<td width="12%" align="left">创建人：</td>
									<td width="41%" align="left"><asp:TextBox ID="txtState" runat="server" TextMode="SingleLine"></asp:TextBox></td>
							</tr>
							<tr>
									<td align="left"><div align="left">标题：</div></td>
									<td colspan="3" align="left">
                                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                    </td>
							</tr>
							<tr>
									<td align="left">状态：</td>
									<td colspan="3" align="left">
                                        <asp:DropDownList ID="DropDownList1" runat="server">
                                            <asp:ListItem Value="1">已入库</asp:ListItem>
                                            <asp:ListItem Selected="True" Value="0">草稿</asp:ListItem>
                                        </asp:DropDownList>
                                    </td>
									</tr>
					</table>
		    </tr>
			<tr>
				    <td align="center" bordercolor="#333333" bgcolor="#33CCFF">
				        <input type="button" name="button5" id="button5" value="加入商品" onclick="newProd();" />
                        <asp:Button ID="Button6" runat="server" Text="保 存" onclick="Button6_Click"  />
                        <input type="button"  name="button6" value="取 消" onclick="top.closeModel(window);"/>
                        <asp:HiddenField ID="txtListData" runat="server" />
                    </td>
		    </tr>
		    <tr>
				    <td bordercolor="#333333">
                        <uc1:dotNetFlexGrid ID="dotNetFlexGrid1" runat="server"  EventOnDbClickFunc="Grid1DbClick"/>
                    </td>
		    </tr>

	    </table>
    </div>
	<div id="divListModify" style="display:none">
        <table width="400px" border="0" cellspacing="0" cellpadding="2">
		    <tr>
				    <td colspan="2" bgcolor="#D9ECFF">录入商品</td>
		    </tr>
		    <tr>
				    <td width="22%">商品名称：</td>
				    <td width="78%"><input type="text" name="txtPName" id="txtPName" /></td>
		    </tr>
		    <tr>
				    <td>数量：</td>
				    <td><input type="text" name="txtPNumber" id="txtPNumber" /></td>
		    </tr>
		    <tr>
				    <td>单价：</td>
				    <td><input type="text" name="txtPPrice" id="txtPPrice" /></td>
		    </tr>
		    <tr>
				    <td>批号：</td>
				    <td><input type="text" name="txtPCode" id="txtPCode" /></td>
		    </tr>
		    <tr>
				    <td colspan="2" align="center" bgcolor="#D9ECFF">
				    <input type="hidden" name="txtOpType"  id="txtOpType" value="" />
				    <input type="hidden" name="txtOpProdId" id="txtOpProdId" value="" />
					
				    <input type="button" name="button3" id="button3" value="确定" onclick="saveModify();"  />
				    <input type="button" name="button4" id="button4" value="取消" onclick="cancelModify();" /></td>
		    </tr>
        </table>
    </div>
</div>
<div style="clear:both"></div>

<div id="divPostback" runat="server" style="color:blue;width:600px">
		<h3>提交的入库单信息</h3>
		<table width="100%" border="0" cellspacing="2" cellpadding="2">
				<tr>
						<td width="15%" align="left"><div align="left">单据编号：</div></td>
						<td width="32%" align="left"><asp:TextBox ID="txtCode0" runat="server" 
                                            TextMode="SingleLine"></asp:TextBox></td>
						<td width="12%" align="left">创建人：</td>
						<td width="41%" align="left"><asp:TextBox ID="txtState0" runat="server" 
                                            TextMode="SingleLine"></asp:TextBox></td>
				</tr>
				<tr>
						<td align="left"><div align="left">标题：</div></td>
						<td colspan="3" align="left"><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
						</td>
				</tr>
				<tr>
						<td align="left">状态：</td>
						<td colspan="3" align="left"><asp:DropDownList ID="DropDownList2" runat="server">
								<asp:ListItem Value="1">已入库</asp:ListItem>
								<asp:ListItem Selected="True" Value="0">草稿</asp:ListItem>
						</asp:DropDownList>
						</td>
				</tr>
		</table>
		<h3>提交的商品列表信息</h3><br />
		<asp:Repeater ID="Repeater1" runat="server">
				<HeaderTemplate>
						<table border="1">
				</HeaderTemplate>
				<ItemTemplate>
						<tr>
								<td><%#Eval("ProductId") %></td>
								<td><%#Eval("ProductName") %></td>
								<td><%#Eval("ProductNumber")%></td>
								<td><%#Eval("ProductPrice")%></td>
								<td><%#Eval("ProductCode")%></td>
								<td><%#Eval("ProductState")%></td>
								<td><%#Eval("OpType") %></td>
						</tr>
				</ItemTemplate>
				<FooterTemplate>
						</table>
				</FooterTemplate>
		</asp:Repeater>
		&nbsp;&nbsp;
		<input type="button" value="保存关闭" onclick="top.closeModel(window);"/>
</div>
<script type="text/javascript">
$(document).ready(JT_init);
</script>
</form>

</body>
</html>
